#include "unit--.h"
using namespace unit_minus;

#include <cstdio>
#include "../WConstants.h"
#include "../WMIConnectionMng.h"
#include "../RegistryManager.h"

testSuite(POCSuite);

testCase(executeQueryTest_local, POCSuite)
{
    cout << "-------- Start WMIConnection::executeQueryTest_local --------" << endl;

	WMIConnectionMng* wmiMng = new WMIConnectionMng();
	wmiMng->initCOMSecurityConfiguration();
	WMIConnection wmiConnection;

	int expected = 0;	
	WHResult* result = wmiMng->createConnection(PC_USER, PC_PASSWORD, PC_NAMESPACE, wmiConnection);
    //TODO: condition if whres is failed
    delete result;

	result = wmiConnection.executeQuery(L"Select * from Win32_OperatingSystem");
	//TODO: condition if whres is failed
	IEnumWbemClassObject* pEnumerator = NULL;
	
	// get IEnumWbemClassObject from the conecction.
	pEnumerator = wmiConnection.getIEnumWbemClassObject();

	IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;
	
	int cont = 0;

	// and we do we want
	while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);

        if(0 == uReturn)
        {
            break;
        }

		cont++;

        pclsObj->Release();
        pclsObj = NULL;
    }	

	assertTrue(!equalValueInfo(0, cont));
	wmiConnection.close();
    delete result;
    cout << "-------- End WMIConnection::executeQueryTest_local Test --------" << endl;
    cout << endl;
    system("PAUSE");
}

/*testCase(executeQueryTest_remote, POCSuite)
{	
	WMIConnectionMng* wmiMng = new WMIConnectionMng();
	WMIConnection wmiConnection;

	int expected = 0;	
	int result = wmiMng->createConnection(PC_USER, PC_PASSWORD, PC_IP_REMOTE_HOST, PC_NAMESPACE, wmiConnection);
		
	WMIConnection *wmiConnection2 = &wmiConnection;

	HRESULT hres = wmiConnection.executeQuery(L"Select * from Win32_OperatingSystem");
	
	IEnumWbemClassObject* pEnumerator = NULL;
	
	// get IEnumWbemClassObject from the conecction.
	pEnumerator = wmiConnection.getIEnumWbemClassObject();
	IWbemClassObject *pclsObj = NULL;
    ULONG uReturn = 0;
	
	int cont = 0;

	// and we do we want
	while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);

        if(0 == uReturn)
        {
            break;
        }

		cont++;

        pclsObj->Release();
        pclsObj = NULL;
    }	

	assertTrue(!equalValueInfo(0, cont));
	wmiConnection.close();	
}*/


//testCase(getClassObjectTest ,POCSuite)
//{	
//	WMIConnectionMng* wmiMng = new WMIConnectionMng();
//	WMIConnection wmiConnection;
//	
//	int result = wmiMng->createConnection(PC_USER, PC_PASSWORD, L"\\ROOT\\DEFAULT", wmiConnection);
//
//	RegistryManager man(&wmiConnection);
// 	RegistryClass* rclass=&RegistryClass();
//	man.getRegistrys(_LOCAL_MACHINE,L"",&rclass);
//
//	wmiConnection.close();
//	delete wmiMng;
//}